Imports System 
Imports System.Text 
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Common
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Configuration 
Imports System.Xml 
Imports System.Xml.Serialization
Imports SubSonic 
Imports SubSonic.Utilities
Namespace Data
    ''' <summary>
    ''' Controller class for aspnet_Membership
    ''' </summary>
		<System.ComponentModel.DataObject()> Public Partial Class AspnetMembershipController
    
        ' Preload our schema..
        Dim thisSchemaLoad As AspnetMembership = New AspnetMembership()
        Private strUserName As String = String.Empty
        Protected ReadOnly Property UserName() As String
            Get
				If strUserName.Length = 0 Then
		        
    				If Not System.Web.HttpContext.Current Is Nothing Then
						strUserName = System.Web.HttpContext.Current.User.Identity.Name
					Else
		        		strUserName = System.Threading.Thread.CurrentPrincipal.Identity.Name
					End If
					Return strUserName
				End If
				Return strUserName
			End Get
        End Property
        <DataObjectMethod(DataObjectMethodType.Select, True)> Public Function FetchAll() As AspnetMembershipCollection
        
            Dim coll As AspnetMembershipCollection = New AspnetMembershipCollection()
            Dim qry As Query = New Query(AspnetMembership.Schema)
            coll.LoadAndCloseReader(qry.ExecuteReader())
            Return coll
            
        End Function
        <DataObjectMethod(DataObjectMethodType.Select, True)> Public Function FetchByID(ByVal UserId As Object) As AspnetMembershipCollection 
        
            Dim coll As AspnetMembershipCollection = New AspnetMembershipCollection().Where("UserId", UserId).Load()
            Return coll
        
        End Function
        
        <DataObjectMethod(DataObjectMethodType.Select, True)> Public Function FetchByQuery(ByVal qry As SubSonic.Query) As AspnetMembershipCollection 
        
            Dim coll As AspnetMembershipCollection = New AspnetMembershipCollection()
            coll.LoadAndCloseReader(qry.ExecuteReader())
            Return coll
        
        End Function
        <DataObjectMethod(DataObjectMethodType.Delete, True)> Public Function Delete(ByVal UserId As Object) as Boolean
        
            Return (AspnetMembership.Delete(UserId) = 1)
        
        End Function
        <DataObjectMethod(DataObjectMethodType.Delete, False)> Public Function Destroy(ByVal UserId As Object) as Boolean
        
            Return (AspnetMembership.Destroy(UserId) = 1)
        
        End Function
        
    	
	    ''' <summary>
	    ''' Inserts a record, can be used with the Object Data Source
	    ''' </summary>
        <DataObjectMethod(DataObjectMethodType.Insert, True)> Public Sub Insert(ByVal ApplicationId As Guid,ByVal UserId As Guid,ByVal Password As String,ByVal PasswordFormat As Integer,ByVal PasswordSalt As String,ByVal MobilePIN As String,ByVal Email As String,ByVal LoweredEmail As String,ByVal PasswordQuestion As String,ByVal PasswordAnswer As String,ByVal IsApproved As Boolean,ByVal IsLockedOut As Boolean,ByVal CreateDate As DateTime,ByVal LastLoginDate As DateTime,ByVal LastPasswordChangedDate As DateTime,ByVal LastLockoutDate As DateTime,ByVal FailedPasswordAttemptCount As Integer,ByVal FailedPasswordAttemptWindowStart As DateTime,ByVal FailedPasswordAnswerAttemptCount As Integer,ByVal FailedPasswordAnswerAttemptWindowStart As DateTime,ByVal Comment As String)
	   
		    Dim item As AspnetMembership = New AspnetMembership()
		    
            item.ApplicationId = ApplicationId
            
            item.UserId = UserId
            
            item.Password = Password
            
            item.PasswordFormat = PasswordFormat
            
            item.PasswordSalt = PasswordSalt
            
            item.MobilePIN = MobilePIN
            
            item.Email = Email
            
            item.LoweredEmail = LoweredEmail
            
            item.PasswordQuestion = PasswordQuestion
            
            item.PasswordAnswer = PasswordAnswer
            
            item.IsApproved = IsApproved
            
            item.IsLockedOut = IsLockedOut
            
            item.CreateDate = CreateDate
            
            item.LastLoginDate = LastLoginDate
            
            item.LastPasswordChangedDate = LastPasswordChangedDate
            
            item.LastLockoutDate = LastLockoutDate
            
            item.FailedPasswordAttemptCount = FailedPasswordAttemptCount
            
            item.FailedPasswordAttemptWindowStart = FailedPasswordAttemptWindowStart
            
            item.FailedPasswordAnswerAttemptCount = FailedPasswordAnswerAttemptCount
            
            item.FailedPasswordAnswerAttemptWindowStart = FailedPasswordAnswerAttemptWindowStart
            
            item.Comment = Comment
            
	    
		    item.Save(UserName)
	   
	   End Sub
    	
	    ''' <summary>
	    ''' Updates a record, can be used with the Object Data Source
	    ''' </summary>
        <DataObjectMethod(DataObjectMethodType.Update, True)> Public Sub Update(ByVal ApplicationId As Guid,ByVal UserId As Guid,ByVal Password As String,ByVal PasswordFormat As Integer,ByVal PasswordSalt As String,ByVal MobilePIN As String,ByVal Email As String,ByVal LoweredEmail As String,ByVal PasswordQuestion As String,ByVal PasswordAnswer As String,ByVal IsApproved As Boolean,ByVal IsLockedOut As Boolean,ByVal CreateDate As DateTime,ByVal LastLoginDate As DateTime,ByVal LastPasswordChangedDate As DateTime,ByVal LastLockoutDate As DateTime,ByVal FailedPasswordAttemptCount As Integer,ByVal FailedPasswordAttemptWindowStart As DateTime,ByVal FailedPasswordAnswerAttemptCount As Integer,ByVal FailedPasswordAnswerAttemptWindowStart As DateTime,ByVal Comment As String)
	    
		    Dim item As AspnetMembership = New AspnetMembership()
		    
				item.ApplicationId = ApplicationId
				
				item.UserId = UserId
				
				item.Password = Password
				
				item.PasswordFormat = PasswordFormat
				
				item.PasswordSalt = PasswordSalt
				
				item.MobilePIN = MobilePIN
				
				item.Email = Email
				
				item.LoweredEmail = LoweredEmail
				
				item.PasswordQuestion = PasswordQuestion
				
				item.PasswordAnswer = PasswordAnswer
				
				item.IsApproved = IsApproved
				
				item.IsLockedOut = IsLockedOut
				
				item.CreateDate = CreateDate
				
				item.LastLoginDate = LastLoginDate
				
				item.LastPasswordChangedDate = LastPasswordChangedDate
				
				item.LastLockoutDate = LastLockoutDate
				
				item.FailedPasswordAttemptCount = FailedPasswordAttemptCount
				
				item.FailedPasswordAttemptWindowStart = FailedPasswordAttemptWindowStart
				
				item.FailedPasswordAnswerAttemptCount = FailedPasswordAnswerAttemptCount
				
				item.FailedPasswordAnswerAttemptWindowStart = FailedPasswordAnswerAttemptWindowStart
				
				item.Comment = Comment
				
		    item.MarkOld()
		    item.Save(UserName)
	    
	    End Sub
    End Class
End Namespace
